package com.kayak.easysp.transbase;

import java.util.Map;

import com.alibaba.dubbo.rpc.RpcException;
import com.kayak.dubbo.bean.ConsumerBean;
import com.kayak.dubbo.bean.RpcBean;
import com.kayak.easysp.util.ConsumerBeanUtil;
import com.kayak.easysp.util.ErrorCodeEasysp;
import com.kayak.easysp.util.TransUtilEasysp;
import com.kayak.exception.ErrorException;

/**
 * 验证是否登录交易父类
 * @date 2016年8月11日 10:56:04
 * */
public abstract class TransBaseVerifyIsLogin extends TransBase {
	
	public void verifyLogin(TransBean transBean) throws ErrorException{
				
		ConsumerBean consumerBean=ConsumerBeanUtil.getConsumerBean(transBean);
		RpcBean rpcBean=null;
		
		try {
			consumerBean.addRequest("head_jsessionid", transBean.getLocalParam("head_jsessionid"));//用户唯一标识符
			consumerBean.addRequest("head_osnumber", transBean.getLocalParam("head_osnumber"));//设备唯一标示符（用来判断是否重复登录）
			
			rpcBean=getCustInfoService.execute(consumerBean);
			TransUtilEasysp.verifyServiceReturn(rpcBean);
			
		} catch (RpcException e) {
			throw new ErrorException(ErrorCodeEasysp.ERROR_9990_CODE,ErrorCodeEasysp.ERROR_9990_MSG);
		}
		Map<String,Object> user_info=(Map<String, Object>) rpcBean.getResponseParam("user_info");	
		transBean.addLocalParam("user_id", user_info.get("user_id"));
		transBean.addLocalParam("user_mobile", user_info.get("mobile"));
		//获取用户安全状态
		ConsumerBean consumerBeanacct=ConsumerBeanUtil.getConsumerBean(transBean, new String[]{"user_id"});
		RpcBean rpc=null;
		try {
			rpc=qryAcctSecurityStepService.execute(consumerBeanacct);		
			TransUtilEasysp.verifyServiceReturn(rpc);
		} catch (RpcException e) {
			throw new ErrorException(ErrorCodeEasysp.ERROR_9990_CODE,ErrorCodeEasysp.ERROR_9990_MSG);
		}
		transBean.addLocalParam("acctstep_list", rpc.getResponseParam("acctstep_list"));
		transBean.addLocalParam("user_info",user_info);
		
	}
	
}
